from db import utils
from logger import logger
from sub_events.base_event import BaseEvent

LOGGER = logger.CustomLogger()

class AllReviewEvent(BaseEvent):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.event_name_zh: str = "全体加分"
        self.event_name_en: str = "All-Group Review"

    def pre_execute(self) -> bool:
        return self.hook.commenter in self.cfg.get("sub_events", {}).get("all_review", {}).get("whitelist_accounts", [])

    def execute(self) :
        """
        给所有组别进行加分
        """
        utils.update_event_force_pass(self.hook, self.event_name_en, self.hook.commenter)
        for group in self.cfg.get("accounts", {}).get("groups"):
            access_token = self.cfg.get("accounts", {}).get("groups")[group]
            response = self.git_client.review(self.hook.pr_number, token=access_token)
            LOGGER.info(f"[{self.hook.pr_number}] {self.hook.commenter} pass {group} to the pr, response code {response.status_code}")
